/**
 * WMS组件库统一导出
 *
 * 提供所有WMS组件的导出入口，方便在项目中统一引用
 * 按照命名规范组织，支持按需引入和全量引入
 */

// 通用组件导出
export { default as WmsPagination } from "./common/WmsPagination.vue";
export { default as WmsTable } from "./common/WmsTable.vue";
export { default as WmsStatusTag } from "./common/WmsStatusTag.vue";
export { default as WmsActionButtons } from "./common/WmsActionButtons.vue";

// 业务组件导出（待添加）
// export { default as WmsWarehouseSelect } from './business/WmsWarehouseSelect.vue';
// export { default as WmsAreaSelect } from './business/WmsAreaSelect.vue';
// export { default as WmsCategoryTree } from './business/WmsCategoryTree.vue';

// 布局组件导出（待添加）
// export { default as WmsPageContainer } from './layout/WmsPageContainer.vue';
// export { default as WmsContentArea } from './layout/WmsContentArea.vue';
// export { default as WmsCardContainer } from './layout/WmsCardContainer.vue';

// 功能组件导出（待添加）
// export { default as WmsBarcodeScanner } from './feature/WmsBarcodeScanner.vue';
// export { default as WmsInventoryAllocator } from './feature/WmsInventoryAllocator.vue';
// export { default as WmsReportGenerator } from './feature/WmsReportGenerator.vue';

// 类型定义导出
export type * from "./types/common";
export type * from "./types/business";
export type * from "./types/table";
export type * from "./types/form";

// 常用配置导出
export { COMMON_ACTIONS, ACTION_PERMISSIONS } from "./constants/actions";

/**
 * WMS组件库版本信息
 */
export const WMS_COMPONENTS_VERSION = "1.0.0";

/**
 * 组件注册映射表
 */
export const COMPONENT_REGISTRY = {
  // 通用组件
  WmsPagination: () => import("./common/WmsPagination.vue"),
  WmsTable: () => import("./common/WmsTable.vue"),
  WmsStatusTag: () => import("./common/WmsStatusTag.vue"),
  WmsActionButtons: () => import("./common/WmsActionButtons.vue"),

  // 业务组件
  // 'WmsWarehouseSelect': () => import('./business/WmsWarehouseSelect.vue'),
  // 'WmsAreaSelect': () => import('./business/WmsAreaSelect.vue'),
  // 'WmsCategoryTree': () => import('./business/WmsCategoryTree.vue'),

  // 布局组件
  // 'WmsPageContainer': () => import('./layout/WmsPageContainer.vue'),
  // 'WmsContentArea': () => import('./layout/WmsContentArea.vue'),
  // 'WmsCardContainer': () => import('./layout/WmsCardContainer.vue'),

  // 功能组件
  // 'WmsBarcodeScanner': () => import('./feature/WmsBarcodeScanner.vue'),
  // 'WmsInventoryAllocator': () => import('./feature/WmsInventoryAllocator.vue'),
  // 'WmsReportGenerator': () => import('./feature/WmsReportGenerator.vue'),
} as const;

/**
 * 组件分类信息
 */
export const COMPONENT_CATEGORIES = {
  common: ["WmsPagination", "WmsTable", "WmsStatusTag", "WmsActionButtons"],
  business: [
    // 'WmsWarehouseSelect',
    // 'WmsAreaSelect',
    // 'WmsCategoryTree',
  ],
  layout: [
    // 'WmsPageContainer',
    // 'WmsContentArea',
    // 'WmsCardContainer',
  ],
  feature: [
    // 'WmsBarcodeScanner',
    // 'WmsInventoryAllocator',
    // 'WmsReportGenerator',
  ],
} as const;

/**
 * 批量注册组件的辅助函数
 *
 * @param app Vue应用实例
 * @param components 要注册的组件列表，默认注册所有组件
 */
export function registerWmsComponents(
  app: any,
  components: string[] = Object.keys(COMPONENT_REGISTRY),
) {
  components.forEach((componentName) => {
    if (COMPONENT_REGISTRY[componentName as keyof typeof COMPONENT_REGISTRY]) {
      app.component(
        componentName,
        COMPONENT_REGISTRY[componentName as keyof typeof COMPONENT_REGISTRY],
      );
    } else {
      console.warn(`未找到组件: ${componentName}`);
    }
  });
}

/**
 * 按分类注册组件的辅助函数
 *
 * @param app Vue应用实例
 * @param categories 要注册的组件分类
 */
export function registerWmsComponentsByCategory(
  app: any,
  categories: (keyof typeof COMPONENT_CATEGORIES)[] = ["common"],
) {
  const components = categories.flatMap(
    (category) => COMPONENT_CATEGORIES[category] || [],
  );
  registerWmsComponents(app, components);
}
